﻿@model IEnumerable<Hrm.Services.ApplicationDto>

@{
    Layout = null;
}

<link href="~/Content/ztree/zTreeStyle.css" rel="stylesheet" />
<style>
    .ztree li span.button.Resource_ico_open, .ztree li span.button.Resource_ico_close {
        background-position: 97px 97px;
        line-height: 1;
        font-size: 13px;
        font-family: 'Glyphicons Halflings';
    }

        .ztree li span.button.Resource_ico_open:before, .ztree li span.button.Resource_ico_close:before {
            content: "\e043";
        }

        .ztree li span.button.Resource_ico_docu {
        background-position: 97px 97px;
        line-height: 1;
        font-size: 13px;
        font-family: 'Glyphicons Halflings';
    }

        .ztree li span.button.Resource_ico_docu:before {
            content: "\e043";
        }

    .ztree li span.button.Permission_ico_docu {
        background-position: 97px 97px;
        line-height: 1;
        font-size: 13px;
        font-family: 'Glyphicons Halflings';
    }

        .ztree li span.button.Permission_ico_docu:before {
            content: "\e022";
        }
</style>
@Html.Hidden("RoleId")
@Html.Hidden("AppId")
<div class="tabs mb20">
    <ul id="ResourceTab" class="nav nav-tabs">
        @foreach (var item in Model)
        {
            <li>
                <a href="#tab_@item.Id" onclick="ResourcePermission.TabClick('@item.Id')" data-toggle="tab">@item.Name</a>
            </li>
        }
    </ul>
    <div id="ResourceTabContent" class="tab-content">
        @foreach (var item in Model)
        {
            <div id="tab_@item.Id">
                <ul id="tree_@item.Id" class="ztree"></ul>
            </div>
        }
    </div>
</div>
<script src="~/Scripts/ztree/jquery.ztree.all-3.5.js"></script>
<script>
    var ResourcePermission = {
        TabClick: function (appId) {
            var roleId = $("#RoleId").val();
            $("#AppId").val(appId);
            $.mainTool.ajax({
                url: "@Url.Action("ResourcePermissionData")",
                data: {
                    appId: appId,
                    roleId: roleId
                },
                success: function (data) {
                    $.fn.zTree.init($("#tree_" + appId), setting, data);
                }
            });
        }
    };
    var setting = {
        check: {
            enable: true,
            chkDisabledInherit: true
        },
        data: {
            key:{
                checked: "Check",
                name: "Name",
                title: "Type"
            },
            simpleData: {
                enable: true,
                idKey: "Id",
                pIdKey:"PId",
            }
        }
    };
    $(document).ready(function () {
        $("#ResourceTabContent").children().first().addClass("tab-pane fade active in");
        $("#ResourceTabContent").children().not(".active").addClass("tab-pane fade");
        $("#ResourceTab").find("a").first().click();
    });

    Roles.ResourcePermissionSubmit=function()
    {
        var roleId = $("#RoleId").val();
        var appId = $("#AppId").val();
        $.mainTool.ajax({
            url: "@Url.Action("ResourcePermissionSubmit")",
            data: {
                list: $.fn.zTree.getZTreeObj("tree_" + appId).getChangeCheckedNodes(),
                roleId:roleId,
            },
        success: function (data) {
        }
    });
    }
</script>